package com.thomas.generator.component.impl;

import com.thomas.generator.component.AbstractGenerator;
import com.thomas.generator.component.CommonUtil;
import com.thomas.generator.util.DbTypeEnum;

import java.sql.*;

/**
 * @author xutao
 * @Package com.thomas.generator.component
 * @Description: ${todo}
 * @date 2019/12/11 10:49
 */
public class MysqlGeneratorImpl extends AbstractGenerator {

    public static String jdbcDriver = "com.mysql.jdbc.Driver";


    @Override
    public String getDBType() {
        return DbTypeEnum.MYSQL.getValue();
    }

    @Override
    public void init() throws Exception {
        CommonUtil.setGeneratorTableName();// 初始化生成的表名
    }

    @Override
    public void generator() throws Exception {
        super.generator();
    }

    @Override
    public void execute() throws Exception {
        super.execute();
    }

    @Override
    public Connection getConnection() {
        return CommonUtil.getConnection(jdbcDriver);
    }

    @Override
    public ResultSet getTableSet() throws Exception {
        DatabaseMetaData databaseMetaData = getConnection().getMetaData();
        return databaseMetaData.getTables(null, "%", "%", new String[]{"TABLE"});
    }

    @Override
    public ResultSet getColumnSet(String tableName) throws Exception {
        DatabaseMetaData databaseMetaData = getConnection().getMetaData();
        return databaseMetaData.getColumns(null, "%", tableName, "%");
    }
}
